Skip to content

fix(lazy-load): fix TMZ violation#243

Merged
huang-julien merged 3 commits intomainfrom
fix/TMZ
Feb 25, 2026
Merged

fix(lazy-load): fix TMZ violation#243
huang-julien merged 3 commits intomainfrom
fix/TMZ

Conversation

@huang-julien
Copy link
Member

@huang-julien huang-julien commented Feb 25, 2026

🔗 Linked issue

#241

📚 Description

avoid TMZ violation. bug doesn't happen client side but vite can replace imports with __vite_ssr_import in SSR code which then can cause a TMZ violation

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nuxt/hints/@nuxt/hints@243

commit: bf802da

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

The change adjusts the lazy-load plugin so generated wrapper statements are inserted after the last import if any imports exist; if there are no imports, wrapper statements are still prepended at the top. Tests were updated to reflect the new ordering in emitted code. Files changed include the plugin implementation and unit test snapshots.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix (TMZ violation in lazy-load) and follows conventional commit format, directly matching the changeset's purpose.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the TMZ violation issue and linking to issue #241 that the code changes address.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/TMZ

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/unit/hydration/lazy-hydration-plugin.test.ts`:
- Around line 182-183: The snapshot contains unnecessary escaped double quotes
(\" ) inside template literals causing no-useless-escape CI failures; update the
snapshots so the imports for __wrapImportedComponent, __wrapMainComponent and
useLazyComponentTracking use normal double quotes (") or switch the surrounding
template literal to single quotes so the escapes are not needed, i.e., replace
occurrences of \"import { __wrapImportedComponent, __wrapMainComponent } from
\\\"@nuxt/hints/runtime/lazy-load/composables\\\";\" and similar lines (and the
ones at the occurrences for useLazyComponentTracking) with unescaped quotes.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4568d9 and b18df56.

📒 Files selected for processing (2)
  • src/plugins/lazy-load.ts
  • test/unit/hydration/lazy-hydration-plugin.test.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/unit/hydration/lazy-hydration-plugin.test.ts (1)

90-101: No test covers the "zero imports" fallback (prepend-at-top) code path.

The skipped imports describe block returns undefined early for files without .vue imports, so the branch in lazy-load.ts that prepends wrapper statements when there are no existing imports is not exercised by any snapshot test.

Consider adding a case such as:

+  it('should prepend wrapper statements when there are no pre-existing imports', async () => {
+    const code = [
+      `const _sfc_main = {}`,
+      `export default _sfc_main`,
+    ].join('\n')
+    // Manually inject a synthetic vue-import scenario or use a fixture
+    // that exercises the zero-import prepend path.
+  })

Would you like me to draft the full test case, or open a new issue to track this coverage gap?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/unit/hydration/lazy-hydration-plugin.test.ts` around lines 90 - 101, Add
a new unit test in the "skipped imports" describe block that covers the "zero
imports" fallback in lazy-load.ts: create code containing only a .vue import
(e.g. `import MyComp from './MyComp.vue'\nexport default {}`), call the existing
transform function (transform(code, '/src/Parent.vue')), and assert the
transformed output exists and matches the snapshot (e.g.
expect(result).toMatchSnapshot()) so the prepend-at-top branch in lazy-load.ts
is exercised; place the test near the other cases referencing the same transform
helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/unit/hydration/lazy-hydration-plugin.test.ts`:
- Around line 90-101: Add a new unit test in the "skipped imports" describe
block that covers the "zero imports" fallback in lazy-load.ts: create code
containing only a .vue import (e.g. `import MyComp from './MyComp.vue'\nexport
default {}`), call the existing transform function (transform(code,
'/src/Parent.vue')), and assert the transformed output exists and matches the
snapshot (e.g. expect(result).toMatchSnapshot()) so the prepend-at-top branch in
lazy-load.ts is exercised; place the test near the other cases referencing the
same transform helper.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b18df56 and bf802da.

📒 Files selected for processing (1)
  • test/unit/hydration/lazy-hydration-plugin.test.ts

@huang-julien huang-julien merged commit 46afdf5 into main Feb 25, 2026
7 checks passed
@huang-julien huang-julien deleted the fix/TMZ branch February 25, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant